package controllers;

import models.User;
import play.mvc.Before;
import play.mvc.Controller;

public class Application extends Controller {

	@Before
	static void addUser() {
		User user = connected();
		if (user != null) {
			renderArgs.put("user", user);
		}
	}

	static void connect(User user) {
		session.put("user", user.email);
	}

	static User connected() {
		if (renderArgs.get("user") != null) {
			return renderArgs.get("user", User.class);
		}
		String username = session.get("user");
		if (username != null) {
			return User.findByEmail(username);
		}
		return null;
	}

	// User Actions
	public static void index() {
		Blog.index();
	}

}